// GTY

#pragma once

#include "CoreMinimal.h"
#include "AbilitySystemInterface.h"
#include "GameFramework/PlayerState.h"
#include "AuraPlayerState.generated.h"

class ULeveUpInfo;
class UAbilitySystemComponent;
class UAttributeSet;

DECLARE_MULTICAST_DELEGATE_OneParam(FOnPlayerStateChanged, int32/*状态值*/);

/**
 * 
 */
UCLASS()
class AURAGAME_API AAuraPlayerState : public APlayerState , public IAbilitySystemInterface
{
	GENERATED_BODY()

public:
	AAuraPlayerState();
	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;//广播等级
	
	virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;// 实现接口 获取属性系统组件
	UAttributeSet* GetAttributeSet() const{return AttributeSet;}// 获取属性

	UPROPERTY(EditDefaultsOnly)
	TObjectPtr<ULeveUpInfo> LevelUpInfo; //设置升级相关数据
	
	FOnPlayerStateChanged OnXPChangedDelegate; //经验值变动委托
	FOnPlayerStateChanged OnLevelChangedDelegate; //等级变动委托
	FOnPlayerStateChanged OnAttributePointsChangedDelegate;//属性点变动委托
	FOnPlayerStateChanged OnSpellPointsChangedDelegate;//法术点变动委托
	FOnPlayerStateChanged OnMoneyChangedDelegate;//金币变动委托
	
	FORCEINLINE int32 GetPlayerLevel() const {return Level;} //获取角色等级
	void AddToLevel(int32 InLevel); //增加等级
	void SetLevel(int32 InLevel); //设置当前等级

	FORCEINLINE int32 GetXP() const {return XP;} //获取角色当前经验值
	void AddToXP(int32 InXP); //增加经验值
	void SetXP(int32 InXP); //设置当前经验值

	//属性点
	FORCEINLINE int32 GetAttributePoints() const {return AttributePoints;} //获取角色当前属性点
	void AddToAttributePoints(int32 InAttributePoints); //增加属性点
	void SetAttributePoints(int32 InAttributePoints); //设置当前属性点

	//法术点
	FORCEINLINE int32 GetSpellPoints() const {return SpellPoints;}
	void AddToSpellPoints(int32 InSpellPoints);
	void SetSpellPoints(int32 InSpellPoints);


	FORCEINLINE int32 GetMoney() const {return Money;}//获取角色当前金币
	void AddToMoney(int32 InMoney);
	void SetMoney(int32 InMoney);

	
protected:
	UPROPERTY(VisibleAnywhere)
	TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent;// 技能系统组件

	UPROPERTY()
	TObjectPtr<UAttributeSet> AttributeSet;	// 属性

private:
	
	UPROPERTY(VisibleAnywhere, ReplicatedUsing=OnRep_AttributePoints)
	int32 AttributePoints = 0;

	UPROPERTY(VisibleAnywhere, ReplicatedUsing=OnReq_SpellPoints)
	int32 SpellPoints = 1;

	UPROPERTY(VisibleAnywhere,ReplicatedUsing=OnReq_Level)
	int32 Level = 1;

	UPROPERTY(VisibleAnywhere,ReplicatedUsing=OnReq_XP)
	int32 XP = 0.f;
	
	UPROPERTY(VisibleAnywhere,ReplicatedUsing=OnReq_Money)
	int32 Money = 0.f;

	UFUNCTION()
	void OnReq_Level(int32 OldLevel);

	UFUNCTION()
	void OnReq_XP(int32 OldXP);

	UFUNCTION()
	void OnReq_Money(int32 OldMoney);

	UFUNCTION()
	void OnRep_AttributePoints(int32 OldAttributePoints);

	UFUNCTION()
	void OnReq_SpellPoints(int32 OldSpellPoint);

	
};


